//
//  Config.h
//  DaMaoMall
//
//  Created by wally on 16/6/2.
//  Copyright © 2016年 鸿鑫互联－wally. All rights reserved.
//

#ifndef Config_h
#define Config_h

//定义返回请求数据的block类型
typedef void (^ReturnValueBlock) (id returnValue);
typedef void (^ErrorCodeBlock) (id errorCode);
typedef void (^FailureBlock)();
typedef void (^NetWorkBlock)(_Bool netConnetState);


#define DMLog(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
/**
 *  __VA_ARGS__是一个可变参数的宏，很少人知道这个宏，这个可变参数的宏是新的C99规范中新增的，目前似乎只有gcc支（VC6.0的编译器不支持）。宏前面加上##的作用在于，当可变参数的个数为0时，这里的##起到把前面多余的","去掉的作用,否则会编译出错, 你可以试试。
 
 __FILE__宏在预编译时会替换成当前的源文件名
 
 3.__LINE__宏在预编译时会替换成当前的行号
 
 4.__FUNCTION__宏在预编译时会替换成当前的函数名称
 
 有了以上这几个宏，特别是有了__VA_ARGS__，调试信息的输出就变得灵活多了。
 */


/**
 *  常见 自定义  NSLog
 Xcode 7.3.1 #ifndef DEBUG 不打印，改为 #ifndef NEED_DEBUG
 */

#ifndef NEED_DEBUG

#define DMLLog(format,...)  NSLog((format), ## __VA_ARGS__);


#else

#define DMLLog(format,...);

#endif

/**
 *  更为详细的日志信息
 */

#ifndef NEED_DEBUG

# define DMMLog(fmt,...) NSLog((@"[文件名：%s]\n" "[函数名:%s]\n" "[行号:%d] \n" fmt),__FILE__,__FUNCTION__,__LINE__,##__VA_ARGS__);

#else

# define DMMLog(...);

#endif

/**
 *  颜色
 */
#pragma mark  /////////////公共颜色的值

#define  CONTENTVIEW_COLOR                0xfffefa
#define mWindow     [[[UIApplication sharedApplication] delegate] window]

#define goodcolor   UIColorFromRGB(0x6c6155)
#define mWriteOrderVC  @"writeOrderVC"
#define mApp_Bg_Color  RGBA(235,235,235,1)
#define mbyTextColor   UIColorFromRGB(0x666666)

//RGB color macro 0X00000
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//RGB color macro with alpha
#define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

//RBG color
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

//颜色值
#define buttonBackgroundColor [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1]
#define BGCOLOR [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
#define RGBCOLOR(r,g,b)		[UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#define brokenNetwork                     @"网络未连接,请检查您的网络设置"
#define networkovertime                   @"网络请求超时"
#define SERVICE_ERROR_MSG                 @"服务器错误"
#define NET_WORK_ERROR                    @"网络连接失败,请检查网络"


#define WEAKSELF typeof(self) __weak weakSelf = self;


/*********
 宏作用:单例生成宏
 使用方法:http://blog.csdn.net/totogo2010/article/details/8373642
 **********/
#define DEFINE_SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;

#define DEFINE_SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}


//字符串不为空
#define STRING_NOT_EMPTY(string) (string !=nil && [string isKindOfClass:[NSString class]] && ![string isEqualToString:@""])

//判断是否登录 (以 ukey 长度判断)
#define ISLOGING  [[[NSUserDefaults standardUserDefaults] objectForKey:UKEY_UESER] length] > 0

// 判断登录
#define GZISLOGING \
if (!ISLOGING) \
{MCLoginView*login = [[MCLoginView alloc] init];\
[self.navigationController pushViewController:login animated:YES];\
return;\
}

//判断是否是iPhone6Plus的设备
#define iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2208), [[UIScreen mainScreen] currentMode].size) : NO)
// 1334*750分辨率；iPhone6 Plus采用5.5寸屏，1920*1080分辨率
//判断是否是iPhone6的设备
#define iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

//判断是否是iphone5的设备
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

//判断是否是iphone4s的设备
#define iPhone4s ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)



// 屏幕宽
#define GetScreenWidth                 ([[UIScreen mainScreen] bounds].size.width)

// 屏幕高
#define GetScreenHeight                ([[UIScreen mainScreen] bounds].size.height)

#define GetCellWith                       ([UIScreen mainScreen].bounds.size.width - 16)

//算 宽加X坐标的和
#define width_x(view)  view.frame.size.width + view.frame.origin.x
//算 高加Y坐标的和
#define height_y(view)  view.frame.size.height + view.frame.origin.y


//获取图片资源
#define GetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
//===================== 坐标
#define UI_NAVIGATION_BAR_HEIGHT        44
#define UI_TOOL_BAR_HEIGHT              44
#define UI_TAB_BAR_HEIGHT               49
#define UI_STATUS_BAR_HEIGHT            20


#define UI_MAINSCREEN_HEIGHT            (GetScreenHeight - UI_STATUS_BAR_HEIGHT)
#define UI_MAINSCREEN_HEIGHT_ROTATE     (GetScreenWidth - UI_STATUS_BAR_HEIGHT)
#define UI_WHOLE_SCREEN_FRAME           CGRectMake(0, 0, GetScreenWidth, UI_SCREEN_HEIGHT)
#define UI_WHOLE_SCREEN_FRAME_ROTATE    CGRectMake(0, 0, GetScreenHeight, UI_SCREEN_WIDTH)
#define UI_MAIN_VIEW_FRAME              CGRectMake(0, UI_STATUS_BAR_HEIGHT, GetScreenWidth, UI_MAINSCREEN_HEIGHT)
#define UI_MAIN_VIEW_FRAME_ROTATE       CGRectMake(0, UI_STATUS_BAR_HEIGHT, GetScreenHeight, UI_MAINSCREEN_HEIGHT_ROTATE)
#define UI_NONAVBAR_VIEW_FRAME          CGRectMake(0, 0, GetScreenWidth, UI_MAINSCREEN_HEIGHT - UI_NAVIGATION_BAR_HEIGHT)
#define UI_APPLICTION_VIEW_FRAME        CGRectMake(0, 0, GetScreenWidth, UI_MAINSCREEN_HEIGHT)



//statusBar 背景图片
#define STATUSBARBG @"statusBar_bg"

// 一些常用方法的宏定义，摘自MVVMReactiveCocoa

#define ST_DOCUMENT_DIRECTORY NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject

#define ST_APP_NAME    ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"])
#define ST_APP_VERSION ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"])
#define ST_APP_BUILD   ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"])



/**
 *  归档
 */
#define AccountFilePath  [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject] stringByAppendingPathComponent:@"account.arch"]

/**
 *  财务管理 订单 筛选
 */
#define ScreeningOffset [UIScreen mainScreen].bounds.size.width - 90

#endif /* Config_h */
